﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SocialPhotosService;
using System.IO;

namespace TestModel
{
    [TestClass]
    public class InitializeData
    {
        private SocialPhotosEntities model;

        [TestMethod]
        public void InitCategories()
        {
            
            try
            {
                model = new SocialPhotosEntities();

                int preCategoryCount = model.Categories.Count();

                Category cat1 = new Category { Name = "Animal" };
                model.AddToCategories(cat1);
                model.AddToCategories(new Category { Name = "Landscape" });
                model.AddToCategories(new Category { Name = "Fun" });
                model.AddToCategories(new Category { Name = "Erotica" });
                model.AddToCategories(new Category { Name = "Black & White" });
                model.AddToCategories(new Category { Name = "Objects" });
                model.AddToCategories(new Category { Name = "Art & Effect" });
                model.AddToCategories(new Category { Name = "Portrait" });

                User user1 = new User { UserName = "Cuong", Password = "123456" };
                User user2 = new User { UserName = "Ha", Password = "123456" };
                model.AddToUsers(user1);
                model.AddToUsers(user2);

                model.AddToCategories(new Category { Name = "Portrait" });
                model.SaveChanges();

                string fileName = @"J:\MIC\Social photos\SocialPhotosService\TestModel\Images\1.gif";
                System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fileStream);
                long totalBytes = new System.IO.FileInfo(fileName).Length;
                byte[] byteArray = binaryReader.ReadBytes((Int32)totalBytes);



                model.AddToPhotos(new Photo { Image = byteArray, RowGuid = Guid.NewGuid(), Thumbnail = byteArray, Category = cat1 , UserUpload = user1});
                model.SaveChanges();

                Assert.AreEqual(1, model.Photos.Count());
            }
            catch (Exception sqlEx)
            {
            }
        }

        [TestMethod]
        public void InitTags()
        {
            //int preTagCount = model.Tags.Count();
            //model.AddToTags(new Tag { Name = "Hanoi" });
            //model.AddToTags(new Tag { Name = "Dog" });
            //model.AddToTags(new Tag { Name = "Cat" });
            //model.AddToTags(new Tag { Name = "Bird" });
            //model.AddToTags(new Tag { Name = "Fish" });
            //model.AddToTags(new Tag { Name = "Woman" });
            //model.AddToTags(new Tag { Name = "Man" });
            //model.AddToTags(new Tag { Name = "Car" });
            //model.AddToTags(new Tag { Name = "Airplane" });
            //model.SaveChanges();
            //Assert.AreEqual(9, model.Tags.Count() - preTagCount);
        }
    }
}
